﻿using System.Collections.Generic;
using System.Data.Services.Common;
using System.Linq;
using System.Xml.Serialization;
using BookStoreService.Core.Repository;

namespace BookStoreService.Core.Models
{
    public class BookStore 
    {
        private readonly IRepository<Book> m_repository;
        private readonly List<Author> m_authors;

        public BookStore(IRepository<Book> repository, List<Author> authors)
        {
            m_repository = repository;
            m_authors = authors;
        }

        public IQueryable<Book> Books
        {
            get { return m_repository.Query(); }
        }

        public IQueryable<Author> Authors
        {
            get
            {
                return m_authors.AsQueryable();
            }
        }


        public void Add(Book book)
        {
            m_repository.Add(book);
        }

        public void SubmitChanges()
        {
            m_repository.SubmitChanges();
        }
    }

    [DataServiceKey("Name")]
    public class Book
    {
        public Book()
        {
        }

        public Book(string name, string description, IList<Author> authors)
        {
            Name = name;
            Description = description;
            Authors = authors;
        }

        [XmlIgnore]
        public IList<Author> Authors { get; set; }

        public string Name { get; set; }

        public string Description { get; set; }


    }

    [DataServiceKeyAttribute("Name")]
    public class Author
    {
        public Author()
        {
        }

        public Author(string name)
        {
            Name = name;
        }

        public string Name { get; set; }
    }



}